

package com.hazelcast.internal.usercodedeployment.impl.filter;

import com.hazelcast.internal.util.collection.ArrayUtils;
import com.hazelcast.internal.util.filter.Filter;

/**
 * Only classes in the whitelist match. No other classes match.
 */
public class ClassWhitelistFilter implements Filter<String> {

    private final String[] whitelist;

    public ClassWhitelistFilter(String... whitelisted) {
        whitelist = ArrayUtils.createCopy(whitelisted);
    }

    @Override
    public boolean accept(String className) {
        for (String blacklisted : whitelist) {
            if (className.startsWith(blacklisted)) {
                return true;
            }
        }
        return false;
    }
}
